import type { User } from '@/type'
import { courseStore } from '@/stores/course'
import { courses } from '@/datasource'
import router from '@/router'

// 登录
export const loginService = (user: User) => {
  //将 user信息 存储到浏览器的 sessionStorage 中。
  sessionStorage.setItem('user', JSON.stringify(user))
  //登录完成后获取课程内容存入缓存
  const coursesR = courseStore().coursesS
  coursesR.value = courses.filter((course) => course.uid === user.uid)
}

export const logoutService = () => {
  //清除登录信息
  sessionStorage.clear()
  router.push('/login')
}
